#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

class Solution {
public:
    bool canReorderDoubled(vector<int>& A) {
        unordered_map<int, int>map;
        for (auto& a : A)
            ++map[a];
        sort(A.begin(), A.end(), [](const int& l, const int& r) {return abs(l) < abs(r); });
        for (int i = 0; i < A.size(); ++i) {
            if (map[A[i]]==0)
                continue;
            --map[A[i]];
            if (map.find(2 * A[i]) != map.end() && map[2 * A[i]] > 0) {
                --map[2 * A[i]];
                continue;
            }
            return false;
        }
        return true;
    }
};